const { getCollectList } = require("../../utils/ModuleStory/ModuleStory")
var ports = require("../../utils/ports.js")
// 获取应用实例
const app = getApp()
// pages/collectList/collectList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    collectList: [],
    collectListPage:[],
    proList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getCollectList()
  },
  getCollectList() {
    var that = this
    var req = {}
    req.ListName = 'collectList'
    req.objectDefineID=app.goodsobjectDefineID
    ports.ModuleStory.getCollectList(req, that)
  },
  //商品详情
  toGoodsDetail(e) {
    wx.navigateTo({
      url: '/pages/proInfo/proInfo?id=' + e.currentTarget.dataset.id,
    })
  },
  //删除收藏
  deleteThisCollect(e) {
    var that = this
    var sessionID = wx.getStorageSync('USER_SESSIONID')
    var collectID = e.currentTarget.dataset.id
    ports.ModuleStory.removeCollect({
      sessionID: sessionID,
      collectID: collectID
    }, that, res => {
      if (res.data.header.code == 0) {
        wx.showToast({
          title: "移除成功！",
          icon: 'none'
        })
        that.getCollectList(sessionID)
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */

  onPullDownRefresh: function () {
    var that = this;
    ports.ModuleAll.PullDownRefresh(that, () => {
      that.getCollectList()
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    ports.ModuleAll.ReachBottom('collectList', that, res => {
      that.getCollectList();
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})